package org.moflon.moca;
import java.io.File;
import org.apache.log4j.BasicConfigurator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.moflon.moca.game.parser.GameParserAdapter;
import org.moflon.util.eMoflonEMFUtil;

import JANDSL.JANDSLFactory;
import JANDSL.Transformer;
import Moca.CodeAdapter;
import Moca.MocaFactory;
import MocaTree.Folder;
import MocaTree.MocaTreePackage;

public class MocaMain 
{

  private static CodeAdapter codeAdapter;

  public static void main(String[] args) 
  {
    BasicConfigurator.configure();

    // Register parsers and unparsers
    codeAdapter = MocaFactory.eINSTANCE.createCodeAdapter();
    codeAdapter.getParser().add(new GameParserAdapter());

    // Perform text-to-tree
    Folder tree = codeAdapter.parse(new File("instances/in/"));

    // Save tree to file
    eMoflonEMFUtil.saveModel(MocaTreePackage.eINSTANCE, tree, "instances/tree.xmi");

    // Transform tree-to-model
    EPackage p = (EPackage) eMoflonEMFUtil.loadModel(EcorePackage.eINSTANCE, "../JANSchach/.temp/JANGame.ecore", null);
    
    ResourceImpl resource = new ResourceImpl(URI.createURI("http://www.moflon.org/JANGame"));
    resource.getContents().add(p);
    
    Transformer trans = JANDSLFactory.eINSTANCE.createTransformer();
    trans.transform(p,tree.getFile().get(0).getRootNode());
    //eMoflonEMFUtil.registerXMIFactoryAsDefault();
    
    eMoflonEMFUtil.saveModel(EcorePackage.eINSTANCE, p, "../JANGame/model/JANGame.ecore");
    // Save model to file
    //TODO
    
    // Transform model-to-tree
    //TODO
    
  }
}